{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from deap import base, creator, tools, gp, algorithms\n",
    "import math\n",
    "import random\n",
    "import operator\n",
    "import time\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import csv\n",
    "import re\n",
    "import copy\n",
    "import json\n",
    "from myFuncTools import *\n",
    "import numpy as np\n",
    "import random\n",
    "import pickle\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "COL_NUM = 0\n",
    "ROW_NUM = 0\n",
    "VARIABLES = list()\n",
    "\n",
    "with open(\"settings.json\") as f:\n",
    "    CONFIG_DICT = json.load(f)\n",
    "\n",
    "FACTOR_SPAN = CONFIG_DICT[\"factor_span\"]\n",
    "FILE_PATH = CONFIG_DICT[\"file_path\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# delete extreme data\n",
    "def del_extreme_MAD(sample):\n",
    "    factor_name = list(sample.columns)\n",
    "    for name in factor_name:\n",
    "        x = sample[name]\n",
    "        median = x.median()\n",
    "        MAD = abs(x - median).median()\n",
    "        x[x>(median+3*1.4826*MAD)] = median+3*1.4826*MAD\n",
    "        x[x<(median-3*1.4826*MAD)] = median-3*1.4826*MAD\n",
    "        sample[name] = x\n",
    "    return sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def standardize(sample):\n",
    "    factor_name = list(sample.columns)\n",
    "    for name in factor_name:\n",
    "        x = sample[name]\n",
    "        sample[name] = (x - np.mean(x))/(np.std(x))\n",
    "    return sample"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def init_data():\n",
    "    start_time = time.time()\n",
    "    with open(FILE_PATH) as f:\n",
    "        raw_data = pd.read_csv(f, sep=\",\", index_col=\"date\", na_values=['#VALUE!', '#DIV/0!'])\n",
    "    # initial data columns = ['', 'date', 'open', 'close', 'high', 'low', 'volume', 'money', 'open_interest']\n",
    "    raw_data = raw_data.iloc[:, 1:]\n",
    "    raw_data[\"AvgPrice\"] = gp_div(raw_data[\"money\"], raw_data[\"volume\"])\n",
    "\n",
    "    global ROW_NUM, COL_NUM, VARIABLES\n",
    "    index_col = raw_data.index\n",
    "\n",
    "    VARIABLES = raw_data.columns\n",
    "    print(\"variables: \", repr(list(VARIABLES)))\n",
    "    ROW_NUM, COL_NUM = raw_data.shape\n",
    "    raw_data = raw_data.values\n",
    "    raw_data = raw_data.astype(np.float64)\n",
    "    raw_data = pd.DataFrame(raw_data, columns=VARIABLES, index=index_col)\n",
    "\n",
    "    raw_data = del_extreme_MAD(raw_data)\n",
    "    raw_data = standardize(raw_data)\n",
    "\n",
    "    end_time = time.time()\n",
    "    print(\"total load data time: \", end_time - start_time)\n",
    "    return raw_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "variables:  ['close', 'high', 'low', 'volume', 'money', 'open_interest', 'AvgPrice']\n",
      "total load data time:  0.4484672546386719\n",
      "VAR_DICT:  {'close': 'var0', 'high': 'var1', 'low': 'var2', 'volume': 'var3', 'money': 'var4', 'open_interest': 'var5', 'AvgPrice': 'var6'}\n"
     ]
    }
   ],
   "source": [
    "all_data = init_data()\n",
    "pset = gp.PrimitiveSet(\"Main\", arity=COL_NUM, prefix=\"var\")\n",
    "VAR_DICT = dict(zip(VARIABLES, pset.arguments))\n",
    "print(\"VAR_DICT: \", VAR_DICT)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "pset.addPrimitive(gp_add, arity=2, name=\"gp_add\")\n",
    "# pset.addPrimitive(gp_sub, arity=2, name=\"gp_sub\")\n",
    "pset.addPrimitive(gp_mul, arity=2, name=\"gp_mul\")\n",
    "# pset.addPrimitive(gp_div, arity=2, name=\"gp_div\")\n",
    "\n",
    "# pset.addPrimitive(gp_tan, arity=1, name=\"gp_tan\")\n",
    "# pset.addPrimitive(gp_sin, arity=1, name=\"gp_sin\")\n",
    "# pset.addPrimitive(gp_cos, arity=1, name=\"gp_cos\")\n",
    "\n",
    "# pset.addPrimitive(gp_abs, arity=1, name=\"gp_abs\")\n",
    "# pset.addPrimitive(gp_inv, arity=1, name=\"gp_inv\")\n",
    "# pset.addPrimitive(gp_neg, arity=1, name=\"gp_neg\")\n",
    "# pset.addPrimitive(gp_log, arity=1, name=\"gp_log\")\n",
    "# pset.addPrimitive(gp_sqrt, arity=1, name=\"gp_sqrt\")\n",
    "# pset.addPrimitive(gp_sigmoid, arity=1, name=\"gp_sigmoid\")\n",
    "pset.addEphemeralConstant(\"rand2\", lambda: random.randint(-10, 10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['var0', 'var1', 'var2', 'var3', 'var4', 'var5', 'var6']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pset.arguments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "var0,var1,var2,var3,var4,var5,var6\n"
     ]
    }
   ],
   "source": [
    "args = \",\".join(arg for arg in pset.arguments)\n",
    "print(args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/tingming/anaconda3/lib/python3.7/site-packages/deap/creator.py:141: RuntimeWarning: A class named 'MultiFitness' has already been created and it will be overwritten. Consider deleting previous creation of that class or rename it.\n",
      "  RuntimeWarning)\n",
      "/home/tingming/anaconda3/lib/python3.7/site-packages/deap/creator.py:141: RuntimeWarning: A class named 'Individual' has already been created and it will be overwritten. Consider deleting previous creation of that class or rename it.\n",
      "  RuntimeWarning)\n"
     ]
    }
   ],
   "source": [
    "creator.create(\"MultiFitness\", base.Fitness, weights=(+1.0,))\n",
    "creator.create(\"Individual\", gp.PrimitiveTree, fitness=creator.MultiFitness)\n",
    "\n",
    "toolbox = base.Toolbox()\n",
    "toolbox.register(\"expr\", gp.genHalfAndHalf, pset=pset, min_=1, max_=2)\n",
    "toolbox.register(\"Individual\", tools.initIterate, creator.Individual, toolbox.expr)\n",
    "toolbox.register(\"population\", tools.initRepeat, list, toolbox.Individual)\n",
    "toolbox.register(\"compile\", gp.compile, pset=pset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "pop = toolbox.population(n=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "ind = toolbox.Individual()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "code = str(ind)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lambda var0,var1,var2,var3,var4,var5,var6: gp_mul(var2, var6)'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "code = \"lambda {args}: {code}\".format(args=args, code=code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lambda var0,var1,var2,var3,var4,var5,var6: gp_mul(var2, var6)'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'__builtins__': None,\n",
       " 'gp_add': <function myFuncTools.gp_add(x, y)>,\n",
       " 'gp_mul': <function myFuncTools.gp_mul(x, y)>}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pset.context"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function <lambda>(var0, var1, var2, var3, var4, var5, var6)>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval(code, pset.context, {})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function __main__.<lambda>(var0, var1, var2, var3, var4, var5, var6)>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval(code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function <lambda>(var0, var1, var2, var3, var4, var5, var6)>"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval(code, pset.context)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eval(epression, globals, locals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evaluate(individual):\n",
    "    # print(\"*\" * 100)\n",
    "    func = toolbox.compile(expr=individual)\n",
    "    # print(\"func: \", str(individual))\n",
    "\n",
    "    temp_data = copy.deepcopy(all_data)\n",
    "\n",
    "    temp = [func(*row) for row in temp_data.values]\n",
    "    index_col = temp_data.index\n",
    "    temp_data[\"factor_value\"] = pd.DataFrame(temp, index=index_col)\n",
    "\n",
    "    # calculate return rate for 2 bar(2 min), use close price\n",
    "    temp_data[\"ret_rate\"] = (temp_data[\"close\"] - temp_data.shift(FACTOR_SPAN)[\"close\"]) / \\\n",
    "                           temp_data.shift(FACTOR_SPAN)[\"close\"]\n",
    "    temp_data.dropna(inplace=True)\n",
    "\n",
    "    # calculate pearson correlation (IC)\n",
    "    ic_ret_factor = temp_data[[\"ret_rate\", \"factor_value\"]].corr(\"pearson\").values[0, 1]\n",
    "    # print(\"ic_ret_factor: \", ic_ret_factor)\n",
    "    # print(\"*\" * 100)\n",
    "    if np.isnan(ic_ret_factor):\n",
    "        temp_data[[\"ret_rate\", \"factor_value\"]].to_csv(\"temp_data.csv\")\n",
    "\n",
    "    return abs(round(ic_ret_factor, 6)),    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "toolbox.register(\"evaluate\", evaluate)\n",
    "toolbox.register(\"select\", tools.selRoulette)\n",
    "toolbox.register(\"mate\", gp.cxOnePoint)\n",
    "toolbox.register(\"expr_mut\", gp.genFull, min_=1, max_=2)\n",
    "toolbox.register(\"mutate\", gp.mutUniform, expr=toolbox.expr_mut, pset=pset)\n",
    "toolbox.decorate(\"mate\", gp.staticLimit(key=operator.attrgetter(\"height\"), max_value=3))\n",
    "toolbox.decorate(\"mutate\", gp.staticLimit(key=operator.attrgetter(\"height\"), max_value=3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def evolve_with_algorithm():\n",
    "    random.seed(318)\n",
    "    pop = toolbox.population(n=10)\n",
    "    hof = tools.HallOfFame(5)\n",
    "\n",
    "    # stats_fit = tools.Statistics(lambda ind: ind.fitness.values)\n",
    "    # stats_size = tools.Statistics(len)\n",
    "    # mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size)\n",
    "    # mstats.register(\"avg\", np.mean, axis=0)\n",
    "    # mstats.register(\"std\", np.std, axis=0)\n",
    "    # mstats.register(\"min\", np.min, axis=0)\n",
    "    # mstats.register(\"max\", np.max, axis=0)\n",
    "\n",
    "    stats = tools.Statistics(lambda ind: ind.fitness.values)\n",
    "    stats.register(\"avg\", np.mean, axis=0)\n",
    "    stats.register(\"std\", np.std, axis=0)\n",
    "    stats.register(\"min\", np.min, axis=0)\n",
    "    stats.register(\"max\", np.max, axis=0)\n",
    "\n",
    "    pop, log = algorithms.eaSimple(pop, toolbox, 0.5, 0.1, 3, stats=stats,\n",
    "                                   halloffame=hof, verbose=True)\n",
    "\n",
    "    return pop, log, hof\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gen\tnevals\tavg        \tstd         \tmin \tmax       \n",
      "0  \t10    \t[0.0040823]\t[0.00983688]\t[0.]\t[0.033431]\n",
      "1  \t6     \t[0.0209633]\t[0.01528831]\t[0.000225]\t[0.033431]\n",
      "2  \t4     \t[0.0237256]\t[0.01484881]\t[0.]      \t[0.033431]\n",
      "3  \t5     \t[0.0234017]\t[0.01532001]\t[0.]      \t[0.033431]\n",
      "gp_sigmoid(gp_div(var0, var1))\n",
      "gp_sigmoid(gp_div(gp_div(var0, var1), var1))\n",
      "gp_add(gp_sqrt(var1), gp_neg(2))\n",
      "gp_add(var0, gp_neg(var1))\n",
      "gp_abs(var5)\n",
      "total_time:  122.7075629234314\n"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    s_time = time.time()\n",
    "    pop, log, hof = evolve_with_algorithm()\n",
    "\n",
    "    for each in hof:\n",
    "        func_str = str(each)\n",
    "        print(func_str)\n",
    "    e_time = time.time()\n",
    "    print(\"total_time: \", e_time - s_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<deap.tools.support.HallOfFame at 0x7fa1081798d0>"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hof"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0.033431,)\n",
      "(0.003239,)\n",
      "(0.00285,)\n",
      "(0.002733,)\n",
      "(0.000741,)\n"
     ]
    }
   ],
   "source": [
    "for ind in hof:\n",
    "    print(str(ind.fitness.values))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.sort?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.033431],\n",
       "       [0.003239],\n",
       "       [0.00285 ],\n",
       "       [0.002733],\n",
       "       [0.000741]])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort([ind.fitness.values for ind in hof])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "func = lambda x: x.fitness.values\n",
    "hof_ls = list(hof)\n",
    "ls = hof_ls.sort(key=func)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "list(hof).sort"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[<deap.gp.Primitive at 0x7fa1166f4b88>,\n",
       "  <deap.gp.Primitive at 0x7fa1166f49a8>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f8360>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f83a8>],\n",
       " [<deap.gp.Primitive at 0x7fa1166f4b88>,\n",
       "  <deap.gp.Primitive at 0x7fa1166f49a8>,\n",
       "  <deap.gp.Primitive at 0x7fa1166f49a8>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f8360>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f83a8>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f83a8>],\n",
       " [<deap.gp.Primitive at 0x7fa1166f4368>,\n",
       "  <deap.gp.Primitive at 0x7fa1166f4b38>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f83a8>,\n",
       "  <deap.gp.Primitive at 0x7fa1166f4778>,\n",
       "  <deap.gp.rand1 at 0x7fa1082219e8>],\n",
       " [<deap.gp.Primitive at 0x7fa108254c28>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f8360>,\n",
       "  <deap.gp.Primitive at 0x7fa1166f4778>,\n",
       "  <deap.gp.Terminal at 0x7fa1166f83a8>],\n",
       " [<deap.gp.Primitive at 0x7fa1166f49f8>, <deap.gp.Terminal at 0x7fa1166f84c8>]]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hof = list(map())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "def evolve_every_gen():\n",
    "    random.seed(318)\n",
    "    pop = toolbox.population(n=10)\n",
    "\n",
    "    # get initial fitness values\n",
    "    fitnesses = list(map(toolbox.evaluate, pop))\n",
    "    for ind, fit in zip(pop, fitnesses):\n",
    "        ind.fitness.values = fit\n",
    "\n",
    "    for gen in range(NGEN):\n",
    "        gen = gen + 1\n",
    "        print(\"-- generation %i --\" % gen)\n",
    "\n",
    "        # select\n",
    "        offspring = toolbox.select(pop, len(pop))\n",
    "        offspring = list(map(toolbox.clone, offspring))\n",
    "\n",
    "        # crossover\n",
    "        for child1, child2 in zip(offspring[::2], offspring[1::2]):\n",
    "            if random.random() < CXPB:\n",
    "                toolbox.mate(child1, child2)\n",
    "                del child1.fitness.values\n",
    "                del child2.fitness.values\n",
    "        # mutate\n",
    "        for mutant in offspring:\n",
    "            if random.random() < MUTPB:\n",
    "                toolbox.mutate(mutant)\n",
    "                del mutant.fitness.values\n",
    "\n",
    "        invalid_ind = [ind for ind in offspring if not ind.fitness.valid]\n",
    "        fitnesses = map(toolbox.evaluate, invalid_ind)\n",
    "        for ind, fit in zip(invalid_ind, fitnesses):\n",
    "            ind.fitness.values = fit\n",
    "\n",
    "        print(\" Evaluated %i individuals. \" % len(invalid_ind))\n",
    "\n",
    "        pop[:] = offspring\n",
    "\n",
    "        fits = [ind.fitness.values[0] for ind in pop]\n",
    "        length = len(pop)\n",
    "        fits_mean = sum(fits) / length\n",
    "        sum2 = sum(x * x for x in fits)\n",
    "        fits_std = abs(sum2 / length - fits_mean ** 2) ** 0.5\n",
    "\n",
    "        print(\" Min ==> %s\" % min(fits))\n",
    "        print(\" Max ==> %s\" % max(fits))\n",
    "        print(\" Avg ==> %s\" % fits_mean)\n",
    "        print(\" std ==> %s\" % fits_std)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "tuple index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-36-72f9f30ab678>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpop\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfitness\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m: tuple index out of range"
     ]
    }
   ],
   "source": [
    "pop[0].fitness.values[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'toolbox' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-10-8faf75aa8b26>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     15\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     16\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 17\u001b[0;31m     \u001b[0mpopulation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtoolbox\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpopulation\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     18\u001b[0m     \u001b[0mstart_gen\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     19\u001b[0m     \u001b[0mhalloffame\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mHallOfFame\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmaxsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'toolbox' is not defined"
     ]
    }
   ],
   "source": [
    "NGEN = 40\n",
    "CXPB = 0.4\n",
    "MUTPB = 0.1\n",
    "freq = 2\n",
    "\n",
    "checkpoint = None\n",
    "if checkpoint:\n",
    "    with open(checkpoint, \"rb\") as cp_file:\n",
    "        cp = pickle.load(cp_file)\n",
    "    population = cp[\"population\"]\n",
    "    start_gen = cp[\"generation\"]\n",
    "    halloffame = cp[\"halloffame\"]\n",
    "    logbook = cp[\"logbook\"]\n",
    "    random.setstate(cp[\"rndstate\"])\n",
    "\n",
    "else:\n",
    "    population = toolbox.population(n=10)\n",
    "    start_gen = 0\n",
    "    halloffame = tools.HallOfFame(maxsize=1)\n",
    "    logbook = tools.Logbook()\n",
    "\n",
    "print(\"start_gen = \", start_gen)\n",
    "    \n",
    "stats = tools.Statistics(lambda x: x.fitness.values)\n",
    "stats.register(\"avg\", np.mean)\n",
    "stats.register(\"max\", np.max)\n",
    "for gen in range(start_gen, NGEN):\n",
    "    population = algorithms.varAnd(population, toolbox, cxpb=CXPB, mutpb=MUTPB)\n",
    "    invalid_ind = [ind for ind in population if not ind.fitness.valid]\n",
    "    fitnesses = toolbox.map(toolbox.evaluate, invalid_ind)\n",
    "    for ind, fit in zip(invalid_ind, fitnesses):\n",
    "        ind.fitness.values = fit\n",
    "    halloffame.update(population)\n",
    "    print(\"gen = {}, \\t halloffame = {}\".format(gen, str(halloffame[0])))\n",
    "\n",
    "    record = stats.compile(population)\n",
    "    logbook.record(gen=gen, evals=len(invalid_ind), **record)\n",
    "\n",
    "    population = toolbox.select(population, k=len(population))\n",
    "\n",
    "    if gen % freq == 0:\n",
    "\n",
    "        cp = dict(population=population, generation=gen, halloffame=halloffame, \n",
    "                  logbook=logbook, rndstate=random.getstate())\n",
    "\n",
    "        with open(\"checkpoint_name.pkl\", \"wb\") as cp_file:\n",
    "            pickle.dump(cp, cp_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'avg': 0.0058406, 'max': 0.008985}"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "record"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"checkpoint_name.pkl\", \"rb\") as cp_file:\n",
    "    cp = pickle.load(cp_file)\n",
    "population = cp[\"population\"]\n",
    "start_gen = cp[\"generation\"]\n",
    "halloffame = cp[\"halloffame\"]\n",
    "logbook = cp[\"logbook\"]\n",
    "random.setstate(cp[\"rndstate\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start_gen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gp_abs(gp_log(gp_sqrt(gp_neg(gp_sqrt(var6)))))'"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(population[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gp_abs(gp_log(gp_sigmoid(gp_log(gp_sqrt(var6)))))'"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str(halloffame[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0004762108050094569"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "toolbox.compile(halloffame[0])(3388.774, 3381.177, 3388.774, 3375.32, 54464, 1835071700, 4407524)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.009008,)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "halloffame[0].fitness.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'gen': 0, 'evals': 10, 'avg': 0.0015565000000000002, 'max': 0.007154},\n",
       " {'gen': 1, 'evals': 9, 'avg': 0.002592, 'max': 0.008985},\n",
       " {'gen': 2, 'evals': 4, 'avg': 0.0040744, 'max': 0.008985},\n",
       " {'gen': 3, 'evals': 0, 'avg': 0.0058499, 'max': 0.008985},\n",
       " {'gen': 4, 'evals': 2, 'avg': 0.0066428, 'max': 0.008985},\n",
       " {'gen': 5, 'evals': 0, 'avg': 0.007439799999999999, 'max': 0.008985},\n",
       " {'gen': 6, 'evals': 6, 'avg': 0.006132, 'max': 0.009008},\n",
       " {'gen': 7, 'evals': 10, 'avg': 0.0040488, 'max': 0.008985},\n",
       " {'gen': 8, 'evals': 7, 'avg': 0.005559, 'max': 0.008985},\n",
       " {'gen': 9, 'evals': 2, 'avg': 0.0061561, 'max': 0.008985},\n",
       " {'gen': 10, 'evals': 8, 'avg': 0.0041428, 'max': 0.008985},\n",
       " {'gen': 11, 'evals': 4, 'avg': 0.006031300000000001, 'max': 0.008985},\n",
       " {'gen': 12, 'evals': 4, 'avg': 0.0066474, 'max': 0.008985},\n",
       " {'gen': 13, 'evals': 6, 'avg': 0.0052307, 'max': 0.008985},\n",
       " {'gen': 14, 'evals': 6, 'avg': 0.007413, 'max': 0.008985},\n",
       " {'gen': 14, 'evals': 6, 'avg': 0.006507499999999999, 'max': 0.008985},\n",
       " {'gen': 14, 'evals': 5, 'avg': 0.005419599999999999, 'max': 0.008985},\n",
       " {'gen': 15, 'evals': 4, 'avg': 0.007233000000000001, 'max': 0.008985},\n",
       " {'gen': 16, 'evals': 6, 'avg': 0.0058406, 'max': 0.008985}]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logbook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20210928203956\n"
     ]
    }
   ],
   "source": [
    "print(time.strftime(\"%Y%m%d%H%M%S\", time.localtime()))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[<deap.gp.Primitive at 0x7fb2d41a8cc8>,\n",
       "  <deap.gp.Primitive at 0x7fb2d41a8cc8>,\n",
       "  <deap.gp.Terminal at 0x7fb2d41a9948>],\n",
       " [<deap.gp.Primitive at 0x7fb2d41a8bd8>,\n",
       "  <deap.gp.Terminal at 0x7fb2d41a9870>,\n",
       "  <deap.gp.Terminal at 0x7fb2d41a9870>]]"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "ind = pop[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ind.fitness.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-09-30 09:49:49,468 - [line:26] - DEBUG: debug\n",
      "2021-09-30 09:49:49,468 - [line:26] - DEBUG: debug\n",
      "2021-09-30 09:49:49,468 - [line:26] - DEBUG: debug\n",
      "2021-09-30 09:49:49,468 - [line:26] - DEBUG: debug\n",
      "2021-09-30 09:49:49,468 - [line:26] - DEBUG: debug\n",
      "2021-09-30 09:49:49,468 - [line:26] - DEBUG: debug\n",
      "DEBUG:all.log:debug\n",
      "2021-09-30 09:49:49,474 - [line:27] - INFO: info [1, 2, 3]\n",
      "2021-09-30 09:49:49,474 - [line:27] - INFO: info [1, 2, 3]\n",
      "2021-09-30 09:49:49,474 - [line:27] - INFO: info [1, 2, 3]\n",
      "2021-09-30 09:49:49,474 - [line:27] - INFO: info [1, 2, 3]\n",
      "2021-09-30 09:49:49,474 - [line:27] - INFO: info [1, 2, 3]\n",
      "2021-09-30 09:49:49,474 - [line:27] - INFO: info [1, 2, 3]\n",
      "INFO:all.log:info [1, 2, 3]\n",
      "2021-09-30 09:49:49,482 - [line:28] - WARNING: warning\n",
      "2021-09-30 09:49:49,482 - [line:28] - WARNING: warning\n",
      "2021-09-30 09:49:49,482 - [line:28] - WARNING: warning\n",
      "2021-09-30 09:49:49,482 - [line:28] - WARNING: warning\n",
      "2021-09-30 09:49:49,482 - [line:28] - WARNING: warning\n",
      "2021-09-30 09:49:49,482 - [line:28] - WARNING: warning\n",
      "WARNING:all.log:warning\n",
      "2021-09-30 09:49:49,485 - [line:29] - ERROR: error\n",
      "2021-09-30 09:49:49,485 - [line:29] - ERROR: error\n",
      "2021-09-30 09:49:49,485 - [line:29] - ERROR: error\n",
      "2021-09-30 09:49:49,485 - [line:29] - ERROR: error\n",
      "2021-09-30 09:49:49,485 - [line:29] - ERROR: error\n",
      "2021-09-30 09:49:49,485 - [line:29] - ERROR: error\n",
      "ERROR:all.log:error\n",
      "2021-09-30 09:49:49,489 - [line:30] - CRITICAL: critical\n",
      "2021-09-30 09:49:49,489 - [line:30] - CRITICAL: critical\n",
      "2021-09-30 09:49:49,489 - [line:30] - CRITICAL: critical\n",
      "2021-09-30 09:49:49,489 - [line:30] - CRITICAL: critical\n",
      "2021-09-30 09:49:49,489 - [line:30] - CRITICAL: critical\n",
      "2021-09-30 09:49:49,489 - [line:30] - CRITICAL: critical\n",
      "CRITICAL:all.log:critical\n",
      "2021-09-30 09:49:49,498 - [line:31] - ERROR: error\n",
      "2021-09-30 09:49:49,498 - [line:31] - ERROR: error\n",
      "2021-09-30 09:49:49,498 - [line:31] - ERROR: error\n",
      "2021-09-30 09:49:49,498 - [line:31] - ERROR: error\n",
      "2021-09-30 09:49:49,498 - [line:31] - ERROR: error\n",
      "2021-09-30 09:49:49,498 - [line:31] - ERROR: error\n",
      "ERROR:error:error\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import logging\n",
    "from logging import handlers\n",
    "\n",
    "class MyLog(object):\n",
    "    level_map = {\"debug\": logging.DEBUG, \"info\": logging.INFO, \"warning\": logging.WARNING,\n",
    "                 \"error\": logging.ERROR, \"critic\": logging.CRITICAL}\n",
    "\n",
    "    def __init__(self, filename, level=\"info\", when=\"D\", backupCount=3,\n",
    "                 fmt=\"%(asctime)s - [line:%(lineno)d] - %(levelname)s: %(message)s\"):\n",
    "        self.logger = logging.getLogger(filename)\n",
    "        format_str = logging.Formatter(fmt)  # set logger format\n",
    "        self.logger.setLevel(self.level_map.get(level))\n",
    "\n",
    "        sh = logging.StreamHandler()  # print on the screen\n",
    "        # set output format on screen\n",
    "        sh.setFormatter(format_str)\n",
    "        th = handlers.TimedRotatingFileHandler(filename=filename, when=when, backupCount=backupCount, encoding=\"utf-8\")\n",
    "        th.setFormatter(format_str)\n",
    "        self.logger.addHandler(sh)\n",
    "        self.logger.addHandler(th)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    log = MyLog(\"all.log\", level=\"debug\")\n",
    "    log.logger.debug(\"debug\")\n",
    "    log.logger.info(\"info {}\".format([1, 2, 3]))\n",
    "    log.logger.warning(\"warning\")\n",
    "    log.logger.error(\"error\")\n",
    "    log.logger.critical(\"critical\")\n",
    "    MyLog(\"error\", level=\"error\").logger.error(\"error\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 94, in __init__\n",
      "    self.log.logger.info(\"======start program======\")\n",
      "Message: '======start program======'\n",
      "Arguments: ()\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 94, in __init__\n",
      "    self.log.logger.info(\"======start program======\")\n",
      "Message: '======start program======'\n",
      "Arguments: ()\n",
      "2021-09-30 09:43:08,824-[line:94] - INFO: ======start program======\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:genetic_program_log.log:======start program======\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 96, in __init__\n",
      "    self.all_data = self.init_data()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 211, in init_data\n",
      "    self.log.logger.info(\"variables you need in this evolution: {}\".format(VARIABLES))\n",
      "Message: \"variables you need in this evolution: Index(['volume', 'volume_lag1', 'volume_lag2', 'ret_rate'], dtype='object')\"\n",
      "Arguments: ()\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 96, in __init__\n",
      "    self.all_data = self.init_data()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 211, in init_data\n",
      "    self.log.logger.info(\"variables you need in this evolution: {}\".format(VARIABLES))\n",
      "Message: \"variables you need in this evolution: Index(['volume', 'volume_lag1', 'volume_lag2', 'ret_rate'], dtype='object')\"\n",
      "Arguments: ()\n",
      "2021-09-30 09:43:09,208-[line:211] - INFO: variables you need in this evolution: Index(['volume', 'volume_lag1', 'volume_lag2', 'ret_rate'], dtype='object')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:genetic_program_log.log:variables you need in this evolution: Index(['volume', 'volume_lag1', 'volume_lag2', 'ret_rate'], dtype='object')\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 96, in __init__\n",
      "    self.all_data = self.init_data()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 221, in init_data\n",
      "    self.log.logger.info(\"total time for loading data: {}\".format(time.time() - start_time))\n",
      "Message: 'total time for loading data: 1.427135944366455'\n",
      "Arguments: ()\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 96, in __init__\n",
      "    self.all_data = self.init_data()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 221, in init_data\n",
      "    self.log.logger.info(\"total time for loading data: {}\".format(time.time() - start_time))\n",
      "Message: 'total time for loading data: 1.427135944366455'\n",
      "Arguments: ()\n",
      "2021-09-30 09:43:10,267-[line:221] - INFO: total time for loading data: 1.427135944366455\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:genetic_program_log.log:total time for loading data: 1.427135944366455\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 105, in __init__\n",
      "    self.log.logger.info(\"input variables dict: {}\".format(VAR_DICT))\n",
      "Message: \"input variables dict: {'volume': 'var0', 'volume_lag1': 'var1', 'volume_lag2': 'var2'}\"\n",
      "Arguments: ()\n",
      "--- Logging error ---\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 1034, in emit\n",
      "    msg = self.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 880, in format\n",
      "    return fmt.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 622, in format\n",
      "    s = self.formatMessage(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 591, in formatMessage\n",
      "    return self._style.format(record)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/logging/__init__.py\", line 433, in format\n",
      "    return self._fmt % record.__dict__\n",
      "TypeError: not enough arguments for format string\n",
      "Call stack:\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 193, in _run_module_as_main\n",
      "    \"__main__\", mod_spec)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n",
      "    exec(code, run_globals)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n",
      "    app.launch_new_instance()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n",
      "    app.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelapp.py\", line 505, in start\n",
      "    self.io_loop.start()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/platform/asyncio.py\", line 148, in start\n",
      "    self.asyncio_loop.run_forever()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 539, in run_forever\n",
      "    self._run_once()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/base_events.py\", line 1775, in _run_once\n",
      "    handle._run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/asyncio/events.py\", line 88, in _run\n",
      "    self._context.run(self._callback, *self._args)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 690, in <lambda>\n",
      "    lambda f: self._run_callback(functools.partial(callback, future))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/ioloop.py\", line 743, in _run_callback\n",
      "    ret = callback()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 781, in inner\n",
      "    self.run()\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 742, in run\n",
      "    yielded = self.gen.send(value)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 357, in process_one\n",
      "    yield gen.maybe_future(dispatch(*args))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 267, in dispatch_shell\n",
      "    yield gen.maybe_future(handler(stream, idents, msg))\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/kernelbase.py\", line 534, in execute_request\n",
      "    user_expressions, allow_stdin,\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/tornado/gen.py\", line 209, in wrapper\n",
      "    yielded = next(result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/ipkernel.py\", line 294, in do_execute\n",
      "    res = shell.run_cell(code, store_history=store_history, silent=silent)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/ipykernel/zmqshell.py\", line 536, in run_cell\n",
      "    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2848, in run_cell\n",
      "    raw_cell, store_history, silent, shell_futures)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 2874, in _run_cell\n",
      "    return runner(coro)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/async_helpers.py\", line 67, in _pseudo_sync_runner\n",
      "    coro.send(None)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3049, in run_cell_async\n",
      "    interactivity=interactivity, compiler=compiler, result=result)\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3214, in run_ast_nodes\n",
      "    if (yield from self.run_code(code, result)):\n",
      "  File \"/home/tingming/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py\", line 3296, in run_code\n",
      "    exec(code_obj, self.user_global_ns, self.user_ns)\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 385, in <module>\n",
      "    fg = FactorGenerator()\n",
      "  File \"<ipython-input-8-6ff688dd0f7e>\", line 105, in __init__\n",
      "    self.log.logger.info(\"input variables dict: {}\".format(VAR_DICT))\n",
      "Message: \"input variables dict: {'volume': 'var0', 'volume_lag1': 'var1', 'volume_lag2': 'var2'}\"\n",
      "Arguments: ()\n",
      "2021-09-30 09:43:10,284-[line:105] - INFO: input variables dict: {'volume': 'var0', 'volume_lag1': 'var1', 'volume_lag2': 'var2'}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:genetic_program_log.log:input variables dict: {'volume': 'var0', 'volume_lag1': 'var1', 'volume_lag2': 'var2'}\n"
     ]
    },
    {
     "ename": "Exception",
     "evalue": "Ephemerals with different functions should be named differently, even between psets.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-6ff688dd0f7e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m    383\u001b[0m     \u001b[0ms_time\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    384\u001b[0m     \u001b[0;31m# fg = FactorGenerator(\"202109291730_checkpoint.pkl\")\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 385\u001b[0;31m     \u001b[0mfg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mFactorGenerator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    386\u001b[0m     \u001b[0mfg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevolve_every_gen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    387\u001b[0m     \u001b[0me_time\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-8-6ff688dd0f7e>\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, checkpoint)\u001b[0m\n\u001b[1;32m    123\u001b[0m         \u001b[0;31m# self.pset.addPrimitive(gp_sigmoid, arity=1, name=\"gp_sigmoid\")\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    124\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 125\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpset\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maddEphemeralConstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"rand101\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mlambda\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mrandom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    126\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    127\u001b[0m         \u001b[0mcreator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"MultiFitnessMax\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbase\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFitness\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mweights\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m1.0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/deap/gp.py\u001b[0m in \u001b[0;36maddEphemeralConstant\u001b[0;34m(self, name, ephemeral)\u001b[0m\n\u001b[1;32m    452\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0maddEphemeralConstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mephemeral\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    453\u001b[0m         \u001b[0;34m\"\"\"Add an ephemeral constant to the set.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 454\u001b[0;31m         \u001b[0mPrimitiveSetTyped\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maddEphemeralConstant\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mephemeral\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m__type__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    455\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    456\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/deap/gp.py\u001b[0m in \u001b[0;36maddEphemeralConstant\u001b[0;34m(self, name, ephemeral, ret_type)\u001b[0m\n\u001b[1;32m    398\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0missubclass\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mclass_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mEphemeral\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    399\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0mclass_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfunc\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mephemeral\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 400\u001b[0;31m                     raise Exception(\"Ephemerals with different functions should \"\n\u001b[0m\u001b[1;32m    401\u001b[0m                                     \"be named differently, even between psets.\")\n\u001b[1;32m    402\u001b[0m                 \u001b[0;32melif\u001b[0m \u001b[0mclass_\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mret\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mret_type\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mException\u001b[0m: Ephemerals with different functions should be named differently, even between psets."
     ]
    }
   ],
   "source": [
    "\n",
    "# !/usr/bin/env python\n",
    "# coding=utf-8\n",
    "\n",
    "\n",
    "from deap import base, creator, tools, gp, algorithms\n",
    "import math, random, operator, time\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import csv, re, logging\n",
    "from logging import handlers\n",
    "import copy, json, pickle\n",
    "from myFuncTools import *\n",
    "\n",
    "\n",
    "COL_NUM = 0\n",
    "VAR_DICT = None\n",
    "VARIABLES = list()\n",
    "\n",
    "with open(\"settings.json\") as f:\n",
    "    CONFIG_DICT = json.load(f)\n",
    "\n",
    "FACTOR_SPAN = CONFIG_DICT[\"factor_span\"]\n",
    "FILE_PATH = CONFIG_DICT[\"file_path\"]\n",
    "NGEN = CONFIG_DICT[\"n_gen\"]\n",
    "CXPB = CONFIG_DICT[\"cross_prob\"]\n",
    "MUTPB = CONFIG_DICT[\"mutate_prob\"]\n",
    "CHECKPOINT_FREQ = CONFIG_DICT[\"checkpoint_freq\"]\n",
    "RAND_SEED = CONFIG_DICT[\"rand_seed\"]\n",
    "INPUT_MATERIAL = CONFIG_DICT[\"input_data_field\"]\n",
    "HOF_SIZE = CONFIG_DICT[\"halloffame_size\"]\n",
    "POP_SIZE = CONFIG_DICT[\"population_size\"]\n",
    "IND_TREE_MIN_HEIGHT = CONFIG_DICT[\"ind_tree_min_height\"]\n",
    "IND_TREE_MAX_HEIGHT = CONFIG_DICT[\"ind_tree_max_height\"]\n",
    "TREE_HEIGHT_LIMIT = CONFIG_DICT[\"tree_height_limit\"]\n",
    "\n",
    "PICKLE_DIR = \"./pickle/\"\n",
    "\n",
    "# with open(FILE_PATH) as f:\n",
    "#     raw_data = pd.read_csv(f, sep=\",\", index_col=\"date\", na_values=['#VALUE!', '#DIV/0!'])\n",
    "# print(raw_data.head(5))\n",
    "# time.sleep(100)\n",
    "# print(\"FILE_PATH = \", FILE_PATH)\n",
    "\n",
    "\n",
    "# delete extreme data\n",
    "def del_extreme_MAD(sample):\n",
    "    factor_name = list(sample.columns)\n",
    "    for name in factor_name:\n",
    "        x = sample[name]\n",
    "        median = x.median()\n",
    "        MAD = abs(x - median).median()\n",
    "        x[x>(median+3*1.4826*MAD)] = median+3*1.4826*MAD\n",
    "        x[x<(median-3*1.4826*MAD)] = median-3*1.4826*MAD\n",
    "        sample[name] = x\n",
    "    return sample\n",
    "\n",
    "\n",
    "def standardize(sample):\n",
    "    factor_name = list(sample.columns)\n",
    "    for name in factor_name:\n",
    "        x = sample[name]\n",
    "        sample[name] = (x - np.mean(x))/(np.std(x))\n",
    "    return sample\n",
    "\n",
    "\n",
    "class MyLog(object):\n",
    "    level_map = {\"debug\": logging.DEBUG, \"info\": logging.INFO, \"warning\": logging.WARNING,\n",
    "                 \"error\": logging.ERROR, \"critic\": logging.CRITICAL}\n",
    "\n",
    "    def __init__(self, filename, level=\"info\", when=\"D\", backupCount=3,\n",
    "                 fmt=\"%(asctime)s-[line:%(lineno)d] - %(levelname)s: %(message)s\"):\n",
    "\n",
    "        self.logger = logging.getLogger(filename)\n",
    "        format_str = logging.Formatter(fmt)  # set logger format\n",
    "        self.logger.setLevel(self.level_map.get(level))\n",
    "\n",
    "#         sh = logging.StreamHandler()  # print on the screen\n",
    "        # set output format on screen\n",
    "#         sh.setFormatter(format_str)\n",
    "        th = handlers.TimedRotatingFileHandler(filename=filename, when=when, backupCount=backupCount, encoding=\"utf-8\")\n",
    "        th.setFormatter(format_str)\n",
    "#         self.logger.addHandler(sh)\n",
    "        self.logger.addHandler(th)\n",
    "\n",
    "\n",
    "class FactorGenerator(object):\n",
    "\n",
    "    def __init__(self, checkpoint=None):  # checkpoint is a input path\n",
    "        global VAR_DICT, CHECKPOINT_FREQ, RAND_SEED\n",
    "\n",
    "        self.log = MyLog(\"genetic_program_log.log\")\n",
    "        self.log.logger.info(\"======start program======\")\n",
    "\n",
    "        self.all_data = self.init_data()\n",
    "        self.invalid_ind = dict()\n",
    "        self.offspring = None   # offspring for mate, mutate and select\n",
    "        self.bravo_flag = False\n",
    "        self.checkpoint_freq = CHECKPOINT_FREQ\n",
    "        random.seed(RAND_SEED)\n",
    "\n",
    "        self.pset = gp.PrimitiveSet(\"Main\", arity=COL_NUM, prefix=\"var\")\n",
    "        VAR_DICT = dict(zip(VARIABLES, self.pset.arguments))\n",
    "        self.log.logger.info(\"input variables dict: {}\".format(VAR_DICT))\n",
    "        self.pset.addPrimitive(gp_add, arity=2, name=\"gp_add\")\n",
    "        self.pset.addPrimitive(gp_sub, arity=2, name=\"gp_sub\")\n",
    "        self.pset.addPrimitive(gp_mul, arity=2, name=\"gp_mul\")\n",
    "        self.pset.addPrimitive(gp_div, arity=2, name=\"gp_div\")\n",
    "\n",
    "        self.pset.addPrimitive(min, arity=2, name=\"gp_min\")\n",
    "        self.pset.addPrimitive(max, arity=2, name=\"gp_max\")\n",
    "\n",
    "        # pset.addPrimitive(gp_tan, arity=1, name=\"gp_tan\")\n",
    "        # pset.addPrimitive(gp_sin, arity=1, name=\"gp_sin\")\n",
    "        # pset.addPrimitive(gp_cos, arity=1, name=\"gp_cos\")\n",
    "\n",
    "        # self.pset.addPrimitive(gp_abs, arity=1, name=\"gp_abs\")\n",
    "        # self.pset.addPrimitive(gp_inv, arity=1, name=\"gp_inv\")\n",
    "        # self.pset.addPrimitive(gp_neg, arity=1, name=\"gp_neg\")\n",
    "        # self.pset.addPrimitive(gp_log, arity=1, name=\"gp_log\")\n",
    "        # self.pset.addPrimitive(gp_sqrt, arity=1, name=\"gp_sqrt\")\n",
    "        # self.pset.addPrimitive(gp_sigmoid, arity=1, name=\"gp_sigmoid\")\n",
    "\n",
    "        self.pset.addEphemeralConstant(\"rand101\", lambda: random.randint(-5, 5))\n",
    "\n",
    "        creator.create(\"MultiFitnessMax\", base.Fitness, weights=(+1.0,))\n",
    "        creator.create(\"Individual\", gp.PrimitiveTree, fitness=creator.MultiFitnessMax)\n",
    "\n",
    "        self.toolbox = base.Toolbox()\n",
    "        self.toolbox.register(\"expr\", gp.genHalfAndHalf, pset=self.pset, min_=IND_TREE_MIN_HEIGHT, max_=IND_TREE_MAX_HEIGHT)\n",
    "        self.toolbox.register(\"Individual\", tools.initIterate, creator.Individual, self.toolbox.expr)\n",
    "        self.toolbox.register(\"population\", tools.initRepeat, list, self.toolbox.Individual)\n",
    "        self.toolbox.register(\"compile\", gp.compile, pset=self.pset)\n",
    "\n",
    "        self.toolbox.register(\"evaluate\", self.evaluate)\n",
    "        self.toolbox.register(\"select\", tools.selRoulette)\n",
    "        self.toolbox.register(\"mate\", gp.cxOnePoint)\n",
    "        self.toolbox.register(\"expr_mut\", gp.genFull, min_=1, max_=3)\n",
    "        self.toolbox.register(\"mutate\", gp.mutUniform, expr=self.toolbox.expr_mut, pset=self.pset)\n",
    "\n",
    "        # set tree height limit\n",
    "        self.toolbox.decorate(\"mate\", gp.staticLimit(key=operator.attrgetter(\"height\"), max_value=TREE_HEIGHT_LIMIT))\n",
    "        self.toolbox.decorate(\"mutate\", gp.staticLimit(key=operator.attrgetter(\"height\"), max_value=TREE_HEIGHT_LIMIT))\n",
    "\n",
    "        global HOF_SIZE, POP_SIZE\n",
    "        if checkpoint:\n",
    "            self.pickle_file_name = PICKLE_DIR + checkpoint\n",
    "            with open(self.pickle_file_name, \"rb\") as cp_file:\n",
    "                cp = pickle.load(cp_file)\n",
    "            self.pop = cp[\"population\"]\n",
    "            self.start_gen = cp[\"generation\"]\n",
    "            self.halloffame = cp[\"halloffame\"]\n",
    "            self.logbook = cp[\"logbook\"]\n",
    "            random.setstate(cp[\"rndstate\"])\n",
    "            self.pickle_file_name = PICKLE_DIR + time.strftime(\"%Y%m%d%H%M\", time.localtime()) + \"_checkpoint.pkl\"\n",
    "        else:\n",
    "            self.pickle_file_name = PICKLE_DIR + time.strftime(\"%Y%m%d%H%M\", time.localtime()) + \"_checkpoint.pkl\"\n",
    "            self.halloffame = tools.HallOfFame(maxsize=HOF_SIZE)\n",
    "            self.logbook = tools.Logbook()\n",
    "            self.start_gen = 0\n",
    "            self.pop = self.toolbox.population(n=POP_SIZE)\n",
    "\n",
    "            # get initial fitness values\n",
    "            self.init_fitness()\n",
    "\n",
    "        self.log.logger.info(\"pickle_file_name: {}\".format(self.pickle_file_name))\n",
    "        self.log.logger.info(\"evolution start from {} generation. \".format(self.start_gen))\n",
    "\n",
    "    def init_fitness(self):\n",
    "        invalid_ind = list()\n",
    "        for i, ind in enumerate(self.pop):\n",
    "            if not ind.fitness.valid:\n",
    "                return_fitness = self.toolbox.evaluate(ind)\n",
    "                if return_fitness == \"func error\":\n",
    "                    self.log.logger.info(\"i={}, fitness is {}, delete ind {}\".format(i, return_fitness, str(ind)))\n",
    "                    invalid_ind.append(i)\n",
    "                elif return_fitness == \"nan error\":\n",
    "                    self.log.logger.info(\"i={}, fitness is {}, delete ind {}\".format(i, return_fitness, str(ind)))\n",
    "                    invalid_ind.append(i)\n",
    "                else:\n",
    "                    ind.fitness.values = return_fitness\n",
    "        for i in reversed(invalid_ind):\n",
    "            self.pop.pop(i)\n",
    "        self.log.logger.info(\"init fitness values: {}\".format(\"*\"*10))\n",
    "        for ind in self.pop:\n",
    "            self.log.logger.info(\"{}, fitness={}\".format(str(ind), ind.fitness.values[0]))\n",
    "        self.log.logger.info(\"{}\".format(\"*\"*10))\n",
    "\n",
    "    def init_data(self):\n",
    "        start_time = time.time()\n",
    "        with open(FILE_PATH) as file:\n",
    "            raw_data = pd.read_csv(file, sep=\",\", index_col=\"date\", na_values=['#VALUE!', '#DIV/0!'])\n",
    "        # initial data columns = ['date', 'open', 'close', 'high', 'low', 'volume', 'money', 'open_interest']\n",
    "        raw_data[\"AvgPrice\"] = gp_div(raw_data[\"money\"], raw_data[\"volume\"])\n",
    "\n",
    "        # calculate return rate for 2 bar(2 min), use close price\n",
    "        raw_data[\"ret_rate\"] = (raw_data[\"close\"] - raw_data.shift(FACTOR_SPAN)[\"close\"]) / \\\n",
    "                               raw_data.shift(FACTOR_SPAN)[\"close\"]\n",
    "\n",
    "        global INPUT_MATERIAL\n",
    "        raw_data[INPUT_MATERIAL[1]] = raw_data[\"volume\"].shift(1)\n",
    "        raw_data[INPUT_MATERIAL[2]] = raw_data[\"volume\"].shift(2)\n",
    "\n",
    "        # all indicator you need\n",
    "        raw_data = raw_data[INPUT_MATERIAL + [\"ret_rate\"]].dropna()\n",
    "\n",
    "        index_col = raw_data.index\n",
    "        global COL_NUM, VARIABLES\n",
    "        VARIABLES = raw_data.columns\n",
    "        self.log.logger.info(\"variables you need in this evolution: {}\".format(VARIABLES))\n",
    "        COL_NUM = raw_data.shape[1] - 1  # subtract 1(ret_rate col)\n",
    "        raw_data = raw_data.values.astype(np.float64)\n",
    "        raw_data = pd.DataFrame(raw_data, columns=VARIABLES, index=index_col)\n",
    "\n",
    "        raw_data.to_csv(\"cal_factor_data.csv\")\n",
    "\n",
    "        raw_data = del_extreme_MAD(raw_data)\n",
    "        raw_data = standardize(raw_data)\n",
    "\n",
    "        self.log.logger.info(\"total time for loading data: {}\".format(time.time() - start_time))\n",
    "\n",
    "        return raw_data\n",
    "\n",
    "    def evaluate(self, individual):\n",
    "        start_time = time.time()\n",
    "        func = self.toolbox.compile(expr=individual)\n",
    "        self.log.logger.info(\"func={}\".format(str(individual)))\n",
    "\n",
    "        temp_data = copy.deepcopy(self.all_data)\n",
    "        try:\n",
    "            temp = [func(*(row[:-1])) for row in temp_data.values]\n",
    "        except Exception as e:\n",
    "            self.log.logger.info(\"func error occurred: {}\".format(e))\n",
    "            return \"func error\"\n",
    "        index_col = temp_data.index\n",
    "        temp_data[\"factor_value\"] = pd.DataFrame(temp, index=index_col)\n",
    "\n",
    "        temp_data = temp_data.astype(np.float64)\n",
    "\n",
    "        # calculate pearson correlation (IC)\n",
    "        ic_ret_factor = temp_data[\"ret_rate\"].corr(temp_data[\"factor_value\"])\n",
    "        self.log.logger.info(\"ic_ret_factor={}\".format(ic_ret_factor))\n",
    "\n",
    "        if np.isnan(ic_ret_factor):\n",
    "            temp_data[[\"ret_rate\", \"factor_value\"]].to_csv(\"temp_data.csv\")\n",
    "            return \"nan error\"\n",
    "\n",
    "        self.log.logger.info(\"factor {}'s calculate time: {}\".format(str(individual),\n",
    "                                                                     round(time.time()-start_time), 3))\n",
    "        return abs(round(ic_ret_factor, 6)),\n",
    "\n",
    "    def update_fitness(self, invalid_dict):\n",
    "        invalid_index = list()\n",
    "        for i, ind in invalid_dict.items():\n",
    "            return_value = self.toolbox.evaluate(ind)\n",
    "            if return_value == \"func error\":\n",
    "                invalid_index.append(i)\n",
    "            elif return_value == \"nan error\":\n",
    "                self.log.logger.info(\"i={}, fitness is {}, delete ind {}\".format(i, return_value, str(ind)))\n",
    "                invalid_index.append(i)\n",
    "            else:\n",
    "                ind.fitness.values = return_value\n",
    "        if len(invalid_index) > 0:\n",
    "            self.log.logger.info(\"pop invalid index: {}\".format(invalid_index))\n",
    "            for index in invalid_index:\n",
    "                self.log.logger.info(\"pop ind={}, index={}\".format(invalid_dict.pop(index), index))\n",
    "            self.log.logger.info(\"{}\".format(\"=\"*10))\n",
    "        return invalid_dict\n",
    "\n",
    "    def evolve_with_algorithm(self):\n",
    "        random.seed(318)\n",
    "        pop = self.toolbox.population(n=10)\n",
    "        hof = tools.HallOfFame(1)\n",
    "        log = None\n",
    "\n",
    "        stats_fit = tools.Statistics(lambda ind: ind.fitness.values)\n",
    "        stats_size = tools.Statistics(len)\n",
    "        mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size)\n",
    "        mstats.register(\"avg\", np.mean, axis=0)\n",
    "        mstats.register(\"std\", np.std, axis=0)\n",
    "        mstats.register(\"min\", np.min, axis=0)\n",
    "        mstats.register(\"max\", np.max, axis=0)\n",
    "\n",
    "        stats = tools.Statistics(lambda ind: ind.fitness.values)\n",
    "        stats.register(\"avg\", np.mean, axis=0)\n",
    "        stats.register(\"std\", np.std, axis=0)\n",
    "        stats.register(\"min\", np.min, axis=0)\n",
    "        stats.register(\"max\", np.max, axis=0)\n",
    "\n",
    "        # implement this algo with self designed manner\n",
    "        pop, log = algorithms.eaSimple(pop, self.toolbox, 0.5, 0.1, 50, stats=stats,\n",
    "                                       halloffame=hof, verbose=True)\n",
    "\n",
    "        stats = tools.Statistics(lambda ind: ind.fitness.values)\n",
    "        stats.register(\"avg\", np.mean, axis=0)\n",
    "        stats.register(\"std\", np.std, axis=0)\n",
    "        stats.register(\"min\", np.min, axis=0)\n",
    "        stats.register(\"max\", np.max, axis=0)\n",
    "\n",
    "        # implement this algo with self designed manner\n",
    "        pop, log = algorithms.eaSimple(pop, self.toolbox, 0.5, 0.1, 50, stats=stats,\n",
    "                                       halloffame=hof, verbose=True)\n",
    "\n",
    "        return pop, log, hof\n",
    "\n",
    "    def evolve_every_gen(self):\n",
    "\n",
    "        for gen in range(self.start_gen, NGEN):\n",
    "            gen += 1\n",
    "\n",
    "            # select\n",
    "            self.offspring = self.toolbox.select(self.pop, len(self.pop))\n",
    "            self.offspring = list(map(self.toolbox.clone, self.offspring))\n",
    "\n",
    "            # crossover\n",
    "            for child1, child2 in zip(self.offspring[::2], self.offspring[1::2]):\n",
    "                if random.random() < CXPB:\n",
    "                    self.toolbox.mate(child1, child2)\n",
    "                    del child1.fitness.values\n",
    "                    del child2.fitness.values\n",
    "            # mutate\n",
    "            for mutant in self.offspring:\n",
    "                if random.random() < MUTPB:\n",
    "                    self.toolbox.mutate(mutant)\n",
    "                    del mutant.fitness.values\n",
    "\n",
    "            for i, ind in enumerate(self.offspring):\n",
    "                if not ind.fitness.valid:\n",
    "                    self.invalid_ind[i] = ind\n",
    "\n",
    "            self.invalid_ind = self.update_fitness(self.invalid_ind)\n",
    "            del_list = list()\n",
    "            for i, ind in enumerate(self.offspring):\n",
    "                if not ind.fitness.valid:\n",
    "                    if i in self.invalid_ind.keys():\n",
    "                        self.offspring[i] = self.invalid_ind[i]\n",
    "                    else:\n",
    "                        del_list.append(i)\n",
    "            for i in reversed(del_list):\n",
    "                self.offspring.pop(i)\n",
    "\n",
    "            self.pop[:] = self.offspring\n",
    "            self.halloffame.update(self.pop)\n",
    "\n",
    "            self.log.logger.info(\"{}\".format(\"=\"*10))\n",
    "\n",
    "            for i, ind in enumerate(self.halloffame):\n",
    "                self.log.logger.info(\"halloffame:{}\".format(str(self.halloffame[i])))\n",
    "                if ind.fitness.values[0] > 0.03:\n",
    "                    if not self.bravo_flag:\n",
    "                        self.bravo_flag = True\n",
    "                    temp_data = copy.deepcopy(self.all_data)\n",
    "                    func = self.toolbox.compile(expr=ind)\n",
    "                    temp = [func(*(row[0:3])) for row in temp_data.values]\n",
    "                    index_col = temp_data.index\n",
    "                    temp_col_name = \"factor_\" + str(ind)\n",
    "                    temp_data[temp_col_name] = pd.DataFrame(temp, index=index_col)\n",
    "                    self.log.logger.info(\"bravo! {}'s fitness: {} larger than 0.01.\".format(str(ind), ind.fitness.values))\n",
    "            if self.bravo_flag:\n",
    "                temp_data.to_csv(\"halloffame.csv\")\n",
    "                self.bravo_flag = False\n",
    "\n",
    "            fits = [ind.fitness.values[0] for ind in self.pop]\n",
    "            length = len(self.pop)\n",
    "            fit_mean = sum(fits) / length\n",
    "            sum2 = sum(x * x for x in fits)\n",
    "            fit_std = abs(sum2 / length - fit_mean ** 2) ** 0.5\n",
    "            fit_min, fit_max = min(fits), max(fits)\n",
    "            self.log.logger.info(\"len={}\\tgen={}\\teval_n={}\\tmin={}\\tmax={}\\tavg={}\\tstd={}\".\n",
    "                  format(len(self.pop), gen, len(self.invalid_ind),\n",
    "                         round(fit_min, 6), round(fit_max, 6),\n",
    "                         round(fit_mean, 6), round(fit_std, 6)))\n",
    "            self.log.logger.info(\"{}\".format(\"=\" * 10))\n",
    "            if gen % self.checkpoint_freq == 0:\n",
    "                cp = dict(population=self.pop, generation=gen, halloffame=self.halloffame,\n",
    "                          logbook=self.logbook, rndstate=random.getstate())\n",
    "                with open(self.pickle_file_name, \"wb\") as cp_file:\n",
    "                    pickle.dump(cp, cp_file)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    s_time = time.time()\n",
    "    # fg = FactorGenerator(\"202109291730_checkpoint.pkl\")\n",
    "    fg = FactorGenerator()\n",
    "    fg.evolve_every_gen()\n",
    "    e_time = time.time()\n",
    "    print(\"total time: \", time.time()-s_time)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"halloffame.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.iloc[:, -1].hist?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.hist?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'factor_gp_max(gp_sub(var2, var1), gp_add(gp_min(gp_min(var1, var2), gp_add(gp_sub(var1, var1), gp_max(gp_add(var1, var1), gp_mul(var1, var2)))), gp_add(-3, var0)))'"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns[-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "gp_max(gp_sub(var2, var1), gp_add(gp_min(gp_min(var1, var2), gp_add(gp_sub(var1, var1), gp_max(gp_add(var1, var1), gp_mul(var1, var2)))), gp_add(-3, var0)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fa16a68e198>"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAD8CAYAAACLrvgBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAGahJREFUeJzt3XGMXeV95vHvs56aOHTBBpdZy2OtnWXaxkCakllwNrurW9yYMY1i/gDJFrtMU0ujUpNNV64Ss5EWbRJLsFvqFkTQeuNZTGRhKE1rK3XWtQxX0UpgDIFgjEM9MV48sYtLbVwmEbBDfvvHeYc9Ge7MvD53hjt3eD7S1ZzzO+859/0Ng5855547VxGBmZlZjn/S6gmYmVn7cGiYmVk2h4aZmWVzaJiZWTaHhpmZZXNomJlZNoeGmZllc2iYmVk2h4aZmWXraPUEptrChQtj6dKllfb96U9/yoUXXji1E5oB3Fd7cV/tZbb09eyzz74eEb8y2bhZFxpLly7lmWeeqbRvvV6nVqtN7YRmAPfVXtxXe5ktfUn6PznjfH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Yj4ZOn22nb/OawmIj70D+DTwN7S+h3AHa2e13n2sBR4sbT+MrAoLS8CXk7L/x1Y12jcTH8Au4DPzqbegI8CPwCupXiDWEeqv/czSXH34KfTckcap1bPvUEvXRT/eF4HfJfizblt3VOpt+PAwjG1WfNzeD4Pn2kUZuOfK+mMiFMA6etlqd6WvabLF78JHGAW9JYu4zwPnAb2AT8G3oiIkTSkPPf3+krbzwGXfrAzzvKnwJeBn6f1S2n/nkYF8DeSnk1/gQJmwc9hFTP+ltsPSNafK5kl2q5XSb8M/AXwhxHxj1KjFoqhDWozsreIeBf4pKT5wF8CH280LH2d8X1J+hxwOiKelVQbLTcY2jY9jfGZiDgp6TJgn6QfTTC23Xo7Lz7TKGT9uZI285qkRQDp6+lUb6teJf0SRWDsiIjvpPKs6A0gIt4A6hSv2cyXNPqLXHnu7/WVtl8MnPlgZzqpzwCfl3Sc4q9RX0dx5tHOPb0nIk6mr6cpQv4aZtHP4flwaBRm458r2Q30peU+itcDRuu3pjs8VgDnRk+xZxoVpxTbgCMR8SelTW3dm6RfSWcYSJoH/DbFi8dPADelYWP7Gu33JuDxSBfLZ4qIuCMiuiJiKcX/P49HxC20cU+jJF0o6Z+OLgOrgBdp85/Dylr9ospMeQA3AH9LcW35q62ez3nO/WHgFPB/KX7LWU9xfXg/cDR9vSSNFcWdYj8GDgE9rZ7/BH39a4rT+heA59PjhnbvDfgE8Fzq60XgP6f6x4CngUHgz4ELUv0jaX0wbf9Yq3uYpL8a8N3Z0lPq4YfpcXj034d2/zms+vA7ws3MLJsvT5mZWTaHhpmZZXNomJlZNoeGmZllc2iYmVk2h4aZmWVzaJiZWTaHhpmZZft/E4vzJDupvtUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "data.iloc[:, -1].hist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "182"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data.iloc[:, -1][data.iloc[:, -1] > 10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10152      24.042544\n",
       "10153      21.981668\n",
       "12963      34.382045\n",
       "12964      22.834081\n",
       "28508      22.923289\n",
       "51875      24.635918\n",
       "58042      31.400987\n",
       "58043      29.343735\n",
       "76918      22.250152\n",
       "76919      22.952381\n",
       "91106      31.748322\n",
       "91107      24.460938\n",
       "100526    197.574123\n",
       "100527    120.101221\n",
       "131072     35.095238\n",
       "131096    563.162192\n",
       "131097    301.617761\n",
       "144512     22.408913\n",
       "Name: factor_gp_max(gp_sub(var2, var1), gp_add(gp_min(gp_min(var1, var2), gp_add(gp_sub(var1, var1), gp_max(gp_add(var1, var1), gp_mul(var1, var2)))), gp_add(-3, var0))), dtype: float64"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.iloc[:, -1][data.iloc[:, -1] > 20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7fa17ff33fd0>]],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABBEAAAHiCAYAAAC+xVR7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzs3Xm8JWddJ/7PlzQJgQAJWwtJoGGIS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U354uAhZK+C/wD+EWvE9hGNXl/FjgB2J4nQBUAAAFASURBVL3czR5gvu2HgF9J2pPm9NCHgAU9jr+a7U2SLqA5OJgCXGN7uaTLgGW2F9PU7QZJa2jOQJhbxi5X8wSOFcAm4CuD8GQGqM77B8CuwM3lM/fTtmez5W2+r1Xm/VVJs2lqugGYX8ZukPQdmoMNgMtsb8sN3HquMm9obqi4sEySjRjYegNIuhGYBewhaS3wLWBnANtXAktonsywBngF+GLpG9h6Q1Xel9Lc2+UnZf/eZHsGsDdwa2nbCfi17T/2PIFtVJH36cD5kjYB/wPmlu294z4yCSlERJ/JIx4jIiIiIiIiokouZ4iIiIiIiIiIKplEiIiIiIiIiIgqmUSIiIiIiIiIiCqZRIiIiIiIiIiIKplEiIiIiIiIiIgqmUSIiIiIiIiIiCqZRIiIiIiIiIiIKplEiIiIiIiIiIgq/wcgnyAeVKF1nQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 720x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "del_extreme_MAD(pd.DataFrame(data.iloc[:, -1])).hist(bins=30, figsize=(10, 8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "random.randint?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"cal_factor_data.csv\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag1</th>\n",
       "      <th>ret_rate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-09-02 09:03</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.349809</td>\n",
       "      <td>0.670241</td>\n",
       "      <td>0.001043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-09-02 09:04</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.911352</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.001688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-09-02 09:05</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>1.241759</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.001454</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-09-02 09:06</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.874294</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>0.001848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-09-02 09:07</td>\n",
       "      <td>0.756859</td>\n",
       "      <td>0.930510</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.000999</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "0  2019-09-02 09:03            0.521915            0.349809   \n",
       "1  2019-09-02 09:04            1.746168            0.911352   \n",
       "2  2019-09-02 09:05            0.711134            1.241759   \n",
       "3  2019-09-02 09:06            1.229436            0.874294   \n",
       "4  2019-09-02 09:07            0.756859            0.930510   \n",
       "\n",
       "   volume_lag1/volume_lag1  ret_rate  \n",
       "0                 0.670241  0.001043  \n",
       "1                 0.521915  0.001688  \n",
       "2                 1.746168  0.001454  \n",
       "3                 0.711134  0.001848  \n",
       "4                 1.229436  0.000999  "
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "factor1 = gp_div(gp_add(gp_mul(var1, 1), gp_min(var1, -2)), gp_div(gp_min(-5, gp_div(gp_max(var2, var1), gp_mul(var0, var2))), gp_sub(var1, -2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"f1\"] = (data[\"volume/volume_lag1\"] + 2) * (data[\"volume/volume_lag2\"] - 2) * (-0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0.832328\n",
       "1    0.815652\n",
       "2    0.411138\n",
       "3    0.727079\n",
       "4    0.589687\n",
       "Name: f1, dtype: float64"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"f1\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0.001043\n",
       "1    0.001688\n",
       "2    0.001454\n",
       "3    0.001848\n",
       "4    0.000999\n",
       "Name: ret_rate, dtype: float64"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"ret_rate\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag1</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>f1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-09-02 09:03</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.349809</td>\n",
       "      <td>0.670241</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>0.832328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-09-02 09:04</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.911352</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.001688</td>\n",
       "      <td>0.815652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-09-02 09:05</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>1.241759</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.001454</td>\n",
       "      <td>0.411138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-09-02 09:06</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.874294</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.727079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-09-02 09:07</td>\n",
       "      <td>0.756859</td>\n",
       "      <td>0.930510</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.000999</td>\n",
       "      <td>0.589687</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "0  2019-09-02 09:03            0.521915            0.349809   \n",
       "1  2019-09-02 09:04            1.746168            0.911352   \n",
       "2  2019-09-02 09:05            0.711134            1.241759   \n",
       "3  2019-09-02 09:06            1.229436            0.874294   \n",
       "4  2019-09-02 09:07            0.756859            0.930510   \n",
       "\n",
       "   volume_lag1/volume_lag1  ret_rate        f1  \n",
       "0                 0.670241  0.001043  0.832328  \n",
       "1                 0.521915  0.001688  0.815652  \n",
       "2                 1.746168  0.001454  0.411138  \n",
       "3                 0.711134  0.001848  0.727079  \n",
       "4                 1.229436  0.000999  0.589687  "
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "158921"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.dropna(inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "158921"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag1</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>f1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>158921.000000</td>\n",
       "      <td>1.589210e+05</td>\n",
       "      <td>1.589210e+05</td>\n",
       "      <td>158921.000000</td>\n",
       "      <td>1.589210e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.240895</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>0.000006</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.837512</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.001106</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>2.479339e-02</td>\n",
       "      <td>-0.075227</td>\n",
       "      <td>-inf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.661751</td>\n",
       "      <td>6.125994e-01</td>\n",
       "      <td>6.617758e-01</td>\n",
       "      <td>-0.000468</td>\n",
       "      <td>2.898026e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.954802</td>\n",
       "      <td>9.520707e-01</td>\n",
       "      <td>9.548023e-01</td>\n",
       "      <td>0.000002</td>\n",
       "      <td>6.227343e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.444721</td>\n",
       "      <td>1.552812e+00</td>\n",
       "      <td>1.444790e+00</td>\n",
       "      <td>0.000487</td>\n",
       "      <td>7.864499e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>564.169884</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>0.039858</td>\n",
       "      <td>3.287603e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       volume/volume_lag1  volume/volume_lag2  volume_lag1/volume_lag1  \\\n",
       "count       158921.000000        1.589210e+05             1.589210e+05   \n",
       "mean             1.240895                 inf                      inf   \n",
       "std              1.837512                 NaN                      NaN   \n",
       "min              0.000000        0.000000e+00             2.479339e-02   \n",
       "25%              0.661751        6.125994e-01             6.617758e-01   \n",
       "50%              0.954802        9.520707e-01             9.548023e-01   \n",
       "75%              1.444721        1.552812e+00             1.444790e+00   \n",
       "max            564.169884                 inf                      inf   \n",
       "\n",
       "            ret_rate            f1  \n",
       "count  158921.000000  1.589210e+05  \n",
       "mean        0.000006          -inf  \n",
       "std         0.001106           NaN  \n",
       "min        -0.075227          -inf  \n",
       "25%        -0.000468  2.898026e-01  \n",
       "50%         0.000002  6.227343e-01  \n",
       "75%         0.000487  7.864499e-01  \n",
       "max         0.039858  3.287603e+00  "
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data[data[\"f1\"] != -np.inf]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag1</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>f1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.240864</td>\n",
       "      <td>1.362899</td>\n",
       "      <td>1.240907</td>\n",
       "      <td>0.000006</td>\n",
       "      <td>-0.593025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.837459</td>\n",
       "      <td>3.315457</td>\n",
       "      <td>1.837519</td>\n",
       "      <td>0.001106</td>\n",
       "      <td>318.873763</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.024793</td>\n",
       "      <td>-0.075227</td>\n",
       "      <td>-127048.522008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.661752</td>\n",
       "      <td>0.612595</td>\n",
       "      <td>0.661764</td>\n",
       "      <td>-0.000468</td>\n",
       "      <td>0.289821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.954802</td>\n",
       "      <td>0.952061</td>\n",
       "      <td>0.954802</td>\n",
       "      <td>0.000002</td>\n",
       "      <td>0.622735</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.444703</td>\n",
       "      <td>1.552784</td>\n",
       "      <td>1.444722</td>\n",
       "      <td>0.000487</td>\n",
       "      <td>0.786450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>564.169884</td>\n",
       "      <td>1124.000000</td>\n",
       "      <td>564.169884</td>\n",
       "      <td>0.039858</td>\n",
       "      <td>3.287603</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       volume/volume_lag1  volume/volume_lag2  volume_lag1/volume_lag1  \\\n",
       "count       158919.000000       158919.000000            158919.000000   \n",
       "mean             1.240864            1.362899                 1.240907   \n",
       "std              1.837459            3.315457                 1.837519   \n",
       "min              0.000000            0.000000                 0.024793   \n",
       "25%              0.661752            0.612595                 0.661764   \n",
       "50%              0.954802            0.952061                 0.954802   \n",
       "75%              1.444703            1.552784                 1.444722   \n",
       "max            564.169884         1124.000000               564.169884   \n",
       "\n",
       "            ret_rate             f1  \n",
       "count  158919.000000  158919.000000  \n",
       "mean        0.000006      -0.593025  \n",
       "std         0.001106     318.873763  \n",
       "min        -0.075227 -127048.522008  \n",
       "25%        -0.000468       0.289821  \n",
       "50%         0.000002       0.622735  \n",
       "75%         0.000487       0.786450  \n",
       "max         0.039858       3.287603  "
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.07017678712560281"
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"f1\"].corr(data[\"ret_rate\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "gp_max(gp_max(gp_sub(var1, var1), gp_sub(var1, var1)), gp_add(gp_min(var1, var2), gp_add(-3, var0)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag1</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>f1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-09-02 09:03</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.349809</td>\n",
       "      <td>0.670241</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>0.832328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-09-02 09:04</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.911352</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.001688</td>\n",
       "      <td>0.815652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-09-02 09:05</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>1.241759</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.001454</td>\n",
       "      <td>0.411138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-09-02 09:06</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.874294</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.727079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-09-02 09:07</td>\n",
       "      <td>0.756859</td>\n",
       "      <td>0.930510</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.000999</td>\n",
       "      <td>0.589687</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "0  2019-09-02 09:03            0.521915            0.349809   \n",
       "1  2019-09-02 09:04            1.746168            0.911352   \n",
       "2  2019-09-02 09:05            0.711134            1.241759   \n",
       "3  2019-09-02 09:06            1.229436            0.874294   \n",
       "4  2019-09-02 09:07            0.756859            0.930510   \n",
       "\n",
       "   volume_lag1/volume_lag1  ret_rate        f1  \n",
       "0                 0.670241  0.001043  0.832328  \n",
       "1                 0.521915  0.001688  0.815652  \n",
       "2                 1.746168  0.001454  0.411138  \n",
       "3                 0.711134  0.001848  0.727079  \n",
       "4                 1.229436  0.000999  0.589687  "
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag2</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>f1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-09-02 09:03</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.349809</td>\n",
       "      <td>0.670241</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>0.832328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-09-02 09:04</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.911352</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.001688</td>\n",
       "      <td>0.815652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-09-02 09:05</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>1.241759</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.001454</td>\n",
       "      <td>0.411138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-09-02 09:06</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.874294</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.727079</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-09-02 09:07</td>\n",
       "      <td>0.756859</td>\n",
       "      <td>0.930510</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.000999</td>\n",
       "      <td>0.589687</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "0  2019-09-02 09:03            0.521915            0.349809   \n",
       "1  2019-09-02 09:04            1.746168            0.911352   \n",
       "2  2019-09-02 09:05            0.711134            1.241759   \n",
       "3  2019-09-02 09:06            1.229436            0.874294   \n",
       "4  2019-09-02 09:07            0.756859            0.930510   \n",
       "\n",
       "   volume_lag1/volume_lag2  ret_rate        f1  \n",
       "0                 0.670241  0.001043  0.832328  \n",
       "1                 0.521915  0.001688  0.815652  \n",
       "2                 1.746168  0.001454  0.411138  \n",
       "3                 0.711134  0.001848  0.727079  \n",
       "4                 1.229436  0.000999  0.589687  "
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"cal_factor_data.csv\")\n",
    "data.rename(columns={\"volume_lag1/volume_lag1\": \"volume_lag1/volume_lag2\"}, inplace=True)\n",
    "\n",
    "data[\"flag\"] = data[\"volume/volume_lag2\"] - data[\"volume_lag1/volume_lag2\"]\n",
    "\n",
    "data_bigger = data[data[\"flag\"] >=0].copy()\n",
    "\n",
    "data_less = data[data[\"flag\"] < 0].copy()\n",
    "\n",
    "data_bigger[\"final\"] = data_bigger[\"volume/volume_lag2\"]\n",
    "\n",
    "data_less[\"final\"] = data_less[\"volume_lag1/volume_lag2\"]\n",
    "\n",
    "aim_data = pd.concat([data_bigger, data_less])\n",
    "\n",
    "data = aim_data.sort_index()\n",
    "\n",
    "data.rename(columns={\"final\":\"f2\"}, inplace=True)\n",
    "data[\"f2\"] = data[\"f2\"] - 3 + data[\"volume/volume_lag1\"]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_test = data.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag2</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>flag</th>\n",
       "      <th>f2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-09-02 09:03</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.349809</td>\n",
       "      <td>0.670241</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>-0.320432</td>\n",
       "      <td>-1.807844</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-09-02 09:04</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.911352</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.001688</td>\n",
       "      <td>0.389437</td>\n",
       "      <td>-0.342479</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-09-02 09:05</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>1.241759</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.001454</td>\n",
       "      <td>-0.504409</td>\n",
       "      <td>-0.542698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-09-02 09:06</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.874294</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.163160</td>\n",
       "      <td>-0.896270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-09-02 09:07</td>\n",
       "      <td>0.756859</td>\n",
       "      <td>0.930510</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.000999</td>\n",
       "      <td>-0.298926</td>\n",
       "      <td>-1.013705</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "0  2019-09-02 09:03            0.521915            0.349809   \n",
       "1  2019-09-02 09:04            1.746168            0.911352   \n",
       "2  2019-09-02 09:05            0.711134            1.241759   \n",
       "3  2019-09-02 09:06            1.229436            0.874294   \n",
       "4  2019-09-02 09:07            0.756859            0.930510   \n",
       "\n",
       "   volume_lag1/volume_lag2  ret_rate      flag        f2  \n",
       "0                 0.670241  0.001043 -0.320432 -1.807844  \n",
       "1                 0.521915  0.001688  0.389437 -0.342479  \n",
       "2                 1.746168  0.001454 -0.504409 -0.542698  \n",
       "3                 0.711134  0.001848  0.163160 -0.896270  \n",
       "4                 1.229436  0.000999 -0.298926 -1.013705  "
      ]
     },
     "execution_count": 220,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "metadata": {},
   "outputs": [],
   "source": [
    "f2_under_zero = data_test[\"f2\"][data_test[\"f2\"] < 0]\n",
    "f2_up_zero = data_test[\"f2\"][data_test[\"f2\"] >= 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 237,
   "metadata": {},
   "outputs": [],
   "source": [
    "f2_under_zero = f2_under_zero - f2_under_zero"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_test[\"f2\"] = f2_under_zero.append(f2_up_zero).sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag2</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>flag</th>\n",
       "      <th>f2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-09-02 09:03</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.349809</td>\n",
       "      <td>0.670241</td>\n",
       "      <td>0.001043</td>\n",
       "      <td>-0.320432</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-09-02 09:04</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.911352</td>\n",
       "      <td>0.521915</td>\n",
       "      <td>0.001688</td>\n",
       "      <td>0.389437</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-09-02 09:05</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>1.241759</td>\n",
       "      <td>1.746168</td>\n",
       "      <td>0.001454</td>\n",
       "      <td>-0.504409</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-09-02 09:06</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.874294</td>\n",
       "      <td>0.711134</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.163160</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-09-02 09:07</td>\n",
       "      <td>0.756859</td>\n",
       "      <td>0.930510</td>\n",
       "      <td>1.229436</td>\n",
       "      <td>0.000999</td>\n",
       "      <td>-0.298926</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "0  2019-09-02 09:03            0.521915            0.349809   \n",
       "1  2019-09-02 09:04            1.746168            0.911352   \n",
       "2  2019-09-02 09:05            0.711134            1.241759   \n",
       "3  2019-09-02 09:06            1.229436            0.874294   \n",
       "4  2019-09-02 09:07            0.756859            0.930510   \n",
       "\n",
       "   volume_lag1/volume_lag2  ret_rate      flag   f2  \n",
       "0                 0.670241  0.001043 -0.320432  0.0  \n",
       "1                 0.521915  0.001688  0.389437  0.0  \n",
       "2                 1.746168  0.001454 -0.504409  0.0  \n",
       "3                 0.711134  0.001848  0.163160  0.0  \n",
       "4                 1.229436  0.000999 -0.298926  0.0  "
      ]
     },
     "execution_count": 240,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag2</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>flag</th>\n",
       "      <th>f2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>158916</th>\n",
       "      <td>2021-09-01 14:56</td>\n",
       "      <td>0.638438</td>\n",
       "      <td>1.214592</td>\n",
       "      <td>1.902443</td>\n",
       "      <td>0.001652</td>\n",
       "      <td>-0.687851</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158917</th>\n",
       "      <td>2021-09-01 14:57</td>\n",
       "      <td>1.009242</td>\n",
       "      <td>0.644338</td>\n",
       "      <td>0.638438</td>\n",
       "      <td>0.000004</td>\n",
       "      <td>0.005900</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158918</th>\n",
       "      <td>2021-09-01 14:58</td>\n",
       "      <td>0.951252</td>\n",
       "      <td>0.960043</td>\n",
       "      <td>1.009242</td>\n",
       "      <td>-0.001224</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158919</th>\n",
       "      <td>2021-09-01 14:59</td>\n",
       "      <td>1.796433</td>\n",
       "      <td>1.708861</td>\n",
       "      <td>0.951252</td>\n",
       "      <td>-0.003608</td>\n",
       "      <td>0.757608</td>\n",
       "      <td>0.505293</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>158920</th>\n",
       "      <td>2021-09-01 15:00</td>\n",
       "      <td>1.253349</td>\n",
       "      <td>2.251557</td>\n",
       "      <td>1.796433</td>\n",
       "      <td>-0.002097</td>\n",
       "      <td>0.455125</td>\n",
       "      <td>0.504906</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    date  volume/volume_lag1  volume/volume_lag2  \\\n",
       "158916  2021-09-01 14:56            0.638438            1.214592   \n",
       "158917  2021-09-01 14:57            1.009242            0.644338   \n",
       "158918  2021-09-01 14:58            0.951252            0.960043   \n",
       "158919  2021-09-01 14:59            1.796433            1.708861   \n",
       "158920  2021-09-01 15:00            1.253349            2.251557   \n",
       "\n",
       "        volume_lag1/volume_lag2  ret_rate      flag        f2  \n",
       "158916                 1.902443  0.001652 -0.687851  0.000000  \n",
       "158917                 0.638438  0.000004  0.005900  0.000000  \n",
       "158918                 1.009242 -0.001224 -0.049198  0.000000  \n",
       "158919                 0.951252 -0.003608  0.757608  0.505293  \n",
       "158920                 1.796433 -0.002097  0.455125  0.504906  "
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_test.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 242,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>volume/volume_lag1</th>\n",
       "      <th>volume/volume_lag2</th>\n",
       "      <th>volume_lag1/volume_lag2</th>\n",
       "      <th>ret_rate</th>\n",
       "      <th>flag</th>\n",
       "      <th>f2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "      <td>158919.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.240864</td>\n",
       "      <td>1.362899</td>\n",
       "      <td>1.240907</td>\n",
       "      <td>0.000006</td>\n",
       "      <td>0.121992</td>\n",
       "      <td>0.638389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>1.837459</td>\n",
       "      <td>3.315457</td>\n",
       "      <td>1.837519</td>\n",
       "      <td>0.001106</td>\n",
       "      <td>3.256943</td>\n",
       "      <td>4.969355</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.024793</td>\n",
       "      <td>-0.075227</td>\n",
       "      <td>-301.617761</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.661752</td>\n",
       "      <td>0.612595</td>\n",
       "      <td>0.661764</td>\n",
       "      <td>-0.000468</td>\n",
       "      <td>-0.346360</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.954802</td>\n",
       "      <td>0.952061</td>\n",
       "      <td>0.954802</td>\n",
       "      <td>0.000002</td>\n",
       "      <td>-0.037306</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.444703</td>\n",
       "      <td>1.552784</td>\n",
       "      <td>1.444722</td>\n",
       "      <td>0.000487</td>\n",
       "      <td>0.367808</td>\n",
       "      <td>0.227651</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>564.169884</td>\n",
       "      <td>1124.000000</td>\n",
       "      <td>564.169884</td>\n",
       "      <td>0.039858</td>\n",
       "      <td>1122.007692</td>\n",
       "      <td>1685.169884</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       volume/volume_lag1  volume/volume_lag2  volume_lag1/volume_lag2  \\\n",
       "count       158919.000000       158919.000000            158919.000000   \n",
       "mean             1.240864            1.362899                 1.240907   \n",
       "std              1.837459            3.315457                 1.837519   \n",
       "min              0.000000            0.000000                 0.024793   \n",
       "25%              0.661752            0.612595                 0.661764   \n",
       "50%              0.954802            0.952061                 0.954802   \n",
       "75%              1.444703            1.552784                 1.444722   \n",
       "max            564.169884         1124.000000               564.169884   \n",
       "\n",
       "            ret_rate           flag             f2  \n",
       "count  158919.000000  158919.000000  158919.000000  \n",
       "mean        0.000006       0.121992       0.638389  \n",
       "std         0.001106       3.256943       4.969355  \n",
       "min        -0.075227    -301.617761       0.000000  \n",
       "25%        -0.000468      -0.346360       0.000000  \n",
       "50%         0.000002      -0.037306       0.000000  \n",
       "75%         0.000487       0.367808       0.227651  \n",
       "max         0.039858    1122.007692    1685.169884  "
      ]
     },
     "execution_count": 242,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_test.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.07784399849784335"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_test[\"f2\"].corr(data_test[\"ret_rate\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
